package com.yonyou.pmclouds.workflow.util;

import com.yonyou.pmclouds.basecom.exception.BusinessException;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateCovertUtil {

    private static final SimpleDateFormat dateFormatUTC = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
    private static final SimpleDateFormat dateFormatStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static String covertUTCToDateStr(String dateStr) throws BusinessException {
        if (dateStr == null) {
            return null;
        }
        try {
            Date date = dateFormatUTC.parse(dateStr);
            return dateFormatStr.format(date);
        } catch (ParseException e) {
            throw new BusinessException(e.getMessage());
        }
    }

    public static String covertDateToUTC(Date date) throws BusinessException{
        if(date == null) {
            return null;
        }
        return dateFormatUTC.format(date);
    }
}
